{include file="public/header" /}
<div class="page">

    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.ds_promotion_xianshi}</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

<div class="dssc-form-default">
    {empty name="xianshi_info"}
    <form id="add_form" action="{:url('Promotionxianshi/xianshi_save')}" method="post">
        {else /}
        <form id="add_form" action="{:url('Promotionxianshi/xianshi_edit_save')}" method="post">
            <input type="hidden" name="xianshi_id" value="{$xianshi_info.xianshi_id}">
            {/empty}
            <dl>
                <dt><i class="required">*</i>{$Think.lang.xianshi_name}{$Think.lang.ds_colon}
                </dt>
                <dd>
                    <input id="xianshi_name" name="xianshi_name" type="text" maxlength="25" class="text w400"
                           value="{present name='xianshi_info'}{$xianshi_info.xianshi_name}{/present}"/>
                    <span></span>
                    <p class="hint">活动名称将显示在限时折扣活动列表中，方便商家管理使用，最多可输入25个字符。</p>
                </dd>
            </dl>
            <dl>
                <dt>活动标题{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="xianshi_title" name="xianshi_title" type="text" maxlength="10" class="text w200"
                           value="{present name='xianshi_info'}{$xianshi_info.xianshi_title}{/present}"/>
                    <span></span>
                    <p class="hint">活动标题是商家对限时折扣活动的别名操作，请使用例如“新品打折”、“月末折扣”类短语表现，最多可输入10个字符；<br/>非必填选项，留空商品优惠价格前将默认显示“限时折扣”字样。</p>
                </dd>
            </dl>
            <dl>
                <dt>活动描述{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="xianshi_explain" name="xianshi_explain" type="text" maxlength="30"
                           class="text w400"
                           value="{present name='xianshi_info'}{$xianshi_info.xianshi_explain}{/present}"/>
                    <span></span>
                    <p class="hint">活动描述是商家对限时折扣活动的补充说明文字，在商品详情页-优惠信息位置显示；<br/>非必填选项，最多可输入30个字符。</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>折扣率：</dt>
                <dd>
                    <input id="discount_rate" name="discount_rate" type="text" maxlength="10" class="text w200"
                           value="{present name='xianshi_info'}{$xianshi_info.discount_rate}{/present}"/>
                    <span></span>
                    <p style="margin-left: 397px;margin-top:-32px;font-size:14px;height:28px; ">%</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>平台承担比例：</dt>
                <dd>
                    <input id="platform_share" name="platform_share" type="text" maxlength="10" class="text w200"
                           value="{present name='xianshi_info'}{$xianshi_info.platform_share}{/present}"/>
                    <span></span>
                    <p style="margin-left: 397px;margin-top:-32px;font-size:14px;height:28px; ">%</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>运营商承担比例：</dt>
                <dd>
                    <input id="proportion_share" name="proportion_share" type="text" maxlength="10" class="text w200"
                           value="{present name='xianshi_info'}{$xianshi_info.proportion_share}{/present}"/>
                    <span></span>
                    <p style="margin-left: 397px;margin-top:-32px;font-size:14px;height:28px; ">%</p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>供应商承担比例：</dt>
                <dd>
                    <input id="supplier_share" name="supplier_share" type="text" maxlength="10" class="text w200"
                           value="{present name='xianshi_info'}{$xianshi_info.supplier_share}{/present}"/>
                    <span></span>
                    <p style="margin-left: 397px;margin-top:-32px;font-size:14px;height:28px; ">%</p>
                    <p class="hint">平台承担比例 + 运营商承担比例 + 供应商承担比例 = 100%。</p>
                </dd>
            </dl>
        
            <dl>
                <dt><i class="required">*</i>开始时间{$Think.lang.ds_colon}
            </dt>
                <dd>
                    <input id="start_time" value="{present name='xianshi_info'}{$xianshi_info.xianshi_starttime|date="Y-m-d H:i:s",###}{/present}" name="start_time" type="text" class="text w130"/><em
                        class="add-on"><i class="iconfont">&#xe8d6;</i></em><span></span>
                    <p class="hint">
                        {notpresent name="isPlatformStore"}{if $current_xianshi_quota.xianshiquota_starttime > 1}
                        {$Think.lang.xianshi_add_start_time_explain}{$current_xianshi_quota.xianshiquota_starttime|date="Y-m-d H:i:s",###}
                        {/if}{/notpresent}
                    </p>
                </dd>
            </dl>
            <dl>
                <dt><i class="required">*</i>结束时间{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="end_time" name="end_time" value="{present name='xianshi_info'}{$xianshi_info.xianshi_end_time|date="Y-m-d H:i:s",###}{/present}" type="text" class="text w130"/><em class="add-on"><i
                        class="iconfont">&#xe8d6;</i></em><span></span>
                    <p class="hint">
                        {notpresent name="isPlatformStore"}
                        {$Think.lang.xianshi_add_end_time_explain}{$current_xianshi_quota.xianshiquota_endtime|date="Y-m-d H:i:s",###}
                        {/notpresent}
                    </p>
                </dd>
            </dl>

            <!-- <dl>
                <dt><i class="required">*</i>购买下限{$Think.lang.ds_colon}</dt>
                <dd>
                    <input id="lower_limit" name="lower_limit" type="text" class="text w130"
                           value="{empty name='xianshi_info'}1{else}{$xianshi_info.xianshi_lower_limit}{/empty}"/><span></span>
                    <p class="hint">参加活动的最低购买数量，默认为1</p>
                </dd>
            </dl> -->
            <dl>
                    <dt><i class="required">*</i>状态{$Think.lang.ds_colon}</dt>
                    <dd class="onoff" style="margin-top: 5px;">
                        <label for="brand_recommend1" class="cb-enable {if $brand_array.xianshi_state == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>开启</span></label>
                        <label for="brand_recommend0" class="cb-disable {if $brand_array.xianshi_state == '2'}selected{/if}" title="{$Think.lang.ds_no}"><span>关闭</span></label>
                        <input id="brand_recommend1" name="status" {if $brand_array.xianshi_state == '1'}checked="checked"{/if} value="1" type="radio">
                        <input id="brand_recommend0" name="status" {if $brand_array.xianshi_state == '2'}checked="checked"{/if} value="2" type="radio"></td>
                    </dd>
            </dl>
            <div class="bottom">
                <input id="submit_button" type="submit" class="submit" value="{$Think.lang.ds_submit}">
            </div>
        </form>
</div>
</div>

<link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css">
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-zh-CN.js"></script>
<script>
    $(function () {

        $('#start_time').datetimepicker({dateFormat: 'yy-mm-dd'});
        $('#end_time').datetimepicker({dateFormat: 'yy-mm-dd'});


            jQuery.validator.methods.greaterThanDate = function (value, element, param) {
                var date1 = new Date(Date.parse(param.replace(/-/g, "/")));
                var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
                return date1 < date2;
            };
            jQuery.validator.methods.lessThanDate = function (value, element, param) {
                var date1 = new Date(Date.parse(param.replace(/-/g, "/")));
                var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
                return date1 > date2;
            };
            jQuery.validator.methods.greaterThanStartDate = function (value, element) {
                var start_date = $("#start_time").val();
                var date1 = new Date(Date.parse(start_date.replace(/-/g, "/")));
                var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
                return date1 < date2;
            };

//页面输入内容验证
            $("#add_form").validate({
                errorPlacement: function (error, element) {
                    var error_td = element.parent('dd').children('span');
                    error_td.append(error);
                },
                onfocusout: false,
                submitHandler: function (form) {
                    ds_ajaxpost('add_form', 'url', "{:url('Promotionxianshi/index')}",1000);
                },
                rules: {
                    xianshi_name: {
                        required: true,
                    //     remote: {
                    //     url :"{:url('Brand/ajax','branch=check_discount_name')}",
                    //     type:'get',
                    //     data:{
                    //         brand_name : function(){
                    //             return $('#xianshi_name').val();
                    //         },
                    //     }
                    // }
                    },
                    discount_rate: {
                        required: true
                    },
                    platform_share: {
                        required: true
                    },
                    proportion_share: {
                        required: true
                    },
                    supplier_share: {
                        required: true
                    },
                    start_time: {
                        required: true,
                        greaterThanDate: "{:date('Y-m-d H:i',@$current_xianshi_quota['xianshiquota_starttime'])}"
                    },
                    end_time: {
                        required: true,

            greaterThanStartDate : true
        },
            lower_limit: {
                required: true,
                    digits:true,
                    min:1
            }
        },
            messages : {
                xianshi_name : {
                    required : '活动名称不能为空',
                    // remote   : '活动名称不可以重复哦~'
                },
                discount_rate : {
                    required : '折扣率不能为空'
                },
                platform_share : {
                    required : '平台承担比例不能为空'
                },
                proportion_share : {
                    required : '运营商承担比例不能为空'
                },
                supplier_share : {
                    required : '供应商承担比例不能为空'
                },
                start_time : {
                    required : '' +
                    '<?php echo sprintf('开始时间不能为空且不能早于%s',@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_starttime']));?>',
                        greaterThanDate : '<i class="iconfont">&#xe64c;</i>' +
                    '<?php echo sprintf('开始时间不能为空且不能早于%s',@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_starttime']));?>'

                },
                end_time : {
                    required : '' +
                        '<?php echo sprintf('结束时间不能为空且不能晚于%s',@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_endtime']));?>',
                        {if !$isPlatformStore}
                    lessThanDate : '<i class="iconfont">&#xe64c;</i>' +
                    '<?php echo sprintf('结束时间不能为空且不能晚于%s',@date('Y-m-d H:i',$current_xianshi_quota['xianshiquota_endtime']));?>',
                        {/if}
                    greaterThanStartDate : '<i class="iconfont">&#xe64c;</i>{$Think.lang.greater_than_start_time}'
                },
                    lower_limit: {
                        required : '<i class="iconfont">&#xe64c;</i>{$Think.lang.purchase_limits_cannot_empty}',
                            digits: '<i class="iconfont">&#xe64c;</i>{$Think.lang.minimum_purchase_must_figure}',
                            min: '<i class="iconfont">&#xe64c;</i>{$Think.lang.buy_lower_limit_minimum}'
                    }
                }
            });
        });
</script>


